package ycj.learn.springcloud.userhystrix.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import ycj.learn.springcloud.core.entities.Res;
import ycj.learn.springcloud.core.entities.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/{id}")
    @HystrixCommand
    public Res getOne(@PathVariable Long id) {

        if (id > 1000) {
            throw new RuntimeException("id 不存在！");
        }

        User user = new User();

        user.setId(id);
        user.setName("A user who is from hystrix 8001");

        return Res.success(user);
    }
}
